<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>扫码收银</title>
		<link rel="stylesheet" href="dist/css/layui.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/shouy.css" />
	</head>

	<body>
		<div class="wrap">
			<div class="sy_header clearfix">
				<div class="sy_hleft">
					<div class="sy_logobox">
						<div class="sy_logo"><img src="img/logo-ma.png"></div>
						<p id="app_name"></p>
					</div>
					<ul class="sy_nav clearfix">
						<li>
							<a href="index.html">
								<div class="iconfont icon-shouyintai"></div>
								<p>快速收银</p>
							</a>
						</li>
						<li>
							<a href="sao_pay.html">
								<div class="iconfont icon-saomashouyin"></div>
								<p>扫码收银</p>
							</a>
						</li>
						<li>
							<a href="product_pay.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>商品收银</p>
							</a>
						</li>
						<li>
							<a href="house.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>房台收银</p>
							</a>
						</li>
						<li>
							<a href="xiaof_member.html">
								<div class="iconfont icon-weibiaoti-"></div>
								<p>我的会员</p>
							</a>
						</li>
						<li>
							<a href="jingybb.html">
								<div class="iconfont icon-jingyingbaobiao"></div>
								<p>经营报表</p>
							</a>
						</li>
					</ul>
				</div>
				<div class="sy_hright">
					<div class="sy_shopbox">
						<div class="sy_simg"><img id="toux" src="" style="background-color: #FFFFFF;"></div>
						<div class="sy_sinfo">
							<p class="sy_snam">店名：<span id="sname"></span></p>
							<p>用户：<span id="user">15973240090</span></p>
							<p class="exit" onclick="exit()">退出登陆</p>
						</div>
					</div>
				</div>
			</div>

			<div class="sy_sconbox clearfix">
				<div class="sy_sptop clearfix">
					<div class="sy_sptl"><span class="iconfont icon-scanBarcode"></span></div>
					<input  type="text" id="no" class="sy_sptsrk" style="width: 85%;" placeholder="请输入扫描商品条形码">
				</div>
				<div class="sy_spcenter">
					<table class="layui-table">
						<colgroup>
							<col width="150">
							<col width="160">
							<col width="90">
							<col width="90">
							<col width="90">
							<col width="90">
							<col width="100">
							<col width="70">
						</colgroup>
						<thead>
							<tr>
								<th>条形码</th>
								<th>名称</th>
								<th>单价</th>
								<th>最高赠送</th>
								<th>最高抵扣</th>
								<th>数量</th>
								<th>小计￥</th>
								<th>操作</th>
							</tr>
						</thead>
					</table>
					<div style="height:380px;overflow-y: auto;">
						<table class="layui-table">
							<colgroup>
								<col width="150">
								<col width="160">
								<col width="90">
								<col width="90">
								<col width="90">
								<col width="90">
								<col width="100">
								<col width="70">
							</colgroup>
							<tbody id="list">
							</tbody>
						</table>
					</div>
					<div id="demo2" style="display: none;"></div>
				</div>
				<div class="sy_spbtnbox">
					<div class="sy_spbl">合计：<span>¥<em id="total">0.00</em></span></div>
					<div class="sy_spbr">
						<button type="button" onclick="sao_pay()" class="sy_spbbtn orange">收款码</button>
						<button type="button" onclick="jiz_tck()" class="sy_spbbtn blue">记账</button>
					</div>
				</div>
			</div>
		</div>

	</body>

</html>
<script src="dist/layui.all.js"></script>
<script src="dist/json2.js"></script>
<script type="text/javascript" src="dist/jquery-1.11.0.min.js"></script>
<script src="dist/layui.all.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script>

$("#no").focus();
reset_key();
	layui.use(['laypage', 'layer'], function() {
		var laypage = layui.laypage,
			layer = layui.layer;
		laypage.render({
			elem: 'demo2',
			count: 100,
			theme: '#1E9FFF'
		});
	});
	$(function() {
			set_info();
	})
	var cart={};
	var loading=false;
	function get_goods(){
		if($("#no").val() == "") {
			return;
		}
		var index = layer.load(1, {
			shade: [0.1, '#fff'] //0.1透明度的白色背景
		});
		if(loading==true){
			layer.msg("请勿频繁操作");
			layer.close(index);
			return false;
		}
		loading=true;
		$.ajax({
			url: APP.api_url + "Sy/get_gooods",
			data: {
				no: $("#no").val(),
				agent_id: getValue("agent_id"),
				app_id	:APP.app_id,
				time:Date.parse( new Date())
			},
			success: function(data) {
				layer.close(index);
				loading=false;
				var gd = data.good;
				var list_html = "";
				if(gd) {
					var total = 0;
					total += gd['total_price'];
					list_html += '<tr id=tr_' + gd['id'] + '>' +
						'<td>' + gd['goods_no'] + '</td>' +
						'<td>' + gd['goods_name'] + '</td>' +
						'<td>' + gd['sale_price'] +'/'+gd['unit'] + '</td>' +
						'<td>' + gd['zs_price'] + '</td>' +
						'<td>' + gd['dk_price'] + '</td>' +
						'<td>' + gd['nums'] + '</td>' +
						'<td>' + gd['total_price'] + '</td>' +
						'<td><a href="#" onclick="remove_gd(' + gd['id'] + ',' + gd['total_price'] + ',this)" class="layui-btn layui-btn-danger layui-btn-mini" >删除</a></td>' +
						'</tr>';
					var good=cart[gd['id']];
					var zs_price=parseFloat(gd['zs_price']);
					var dk_price=parseFloat(gd['dk_price']);
					if(good){
						good['num']=good['num']+parseFloat(gd['nums']);
						good['total_zs']=good['total_zs']+zs_price;
						good['total_dk']=good['total_dk']+dk_price;
						cart[gd['id']]=good;
					}else{
						good={};
						good["id"]=gd['id'];
						good['price']=gd['sale_price'];
						good['name']=gd['goods_name'];
						good['unit']=gd['unit'];
						good['num']=parseFloat(gd['nums']);
						good['total_zs']=zs_price;
						good['total_dk']=dk_price;
						good['zs']=zs_price;
						good['dk']=dk_price;
						cart[gd['id']]=good;
					}
					$("#total").text((parseFloat($("#total").text())+parseFloat(total)).toFixed(2));
					$("#no").val('');
				} else {
					//list_html = "<tr><td colspan='6'>未查到相关商品信息</td></tr>";
				}
				$("#list").append(list_html);
				$("#no").focus();
			}
		})
	}
	
	function sao_pay() {
		var price = parseFloat($("#total").text());
		if(price == "" || isNaN(price)) {
			layer.msg("账单为空!");
			return false;
		}
		$.ajax({
			url: APP.api_url + "Sy/get_goodssk",
			data: {
				agent_id: getValue("agent_id"),
				emp_id: getValue("id"),
				price: price,
				chain_id: getValue("chain_id"),
				type:2,
				goods:cart,
				app_id	:APP.app_id,
				time:Date.parse( new Date())
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				topay_common(data,price,2);
				set_keyup(2);
			}
		})
	}

	function remove_gd(id, price,obj) {
		var total = parseFloat($("#total").text());
		$("#total").text((total - price).toFixed(2));
		$(obj).parent().parent().remove();
		cart[id]['num']=cart[id]['num']-1;
		var zs=cart[id]['zs'];
		var dk=cart[id]['dk'];
		cart[id]['total_zs']=cart[id]['total_zs']-zs;
		cart[id]['total_dk']=cart[id]['total_dk']-dk;
		//$("#tr_" + id).remove();
		//location.reload();
	}

	function jiz_tck() {
		var price = parseFloat($("#total").text());
		if(price == "" || isNaN(price)) {
			layer.msg("账单为空!");
			return false;
		}
		var con = layer.confirm('确认操作?', function(index) {
			$.ajax({
				url: APP.api_url + "Sy/jizhang",
				data: {
					agent_id: getValue("agent_id"),
					emp_id: getValue("id"),
					price: price,
					oem_id: getValue("oem_id"),
					chain_id: getValue("chain_id"),
					type:2,
					goods:cart,
					app_id	:APP.app_id,
					time:Date.parse( new Date())
				},
				//成功了的回调，并且带有返回值
				success: function(data) {
					layer.close(con);
					jz_common(data,price,2);
				}
			})

		});

	}
</script>